package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @className: NursingProjectServiceImpl
 * @description:
 * @author: InnovatorX
 * @date: 2024/5/26 14:18
 * @Version: 1.0
 */
@Slf4j
@Service
public class NursingProjectServiceImpl implements NursingProjectService {
    @Autowired
    private NursingProjectMapper nursingProjectMapper;

    @Override
    public PageResponse<NursingProjectVo> findByPage(String name, Integer status, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        Page<NursingProjectVo> nursingProjects = nursingProjectMapper.selectByPage(name, status);
        PageResponse<NursingProjectVo> projectVoPageResponse = PageResponse.of(nursingProjects, NursingProjectVo.class);
        return projectVoPageResponse;
    }

    @Override
    public void save(NursingProjectVo nursingProject) {
        nursingProject.setStatus(0);
        nursingProjectMapper.save(nursingProject);
    }

    @Override
    public NursingProjectVo findById(Long id) {
        return nursingProjectMapper.findById(id);
    }

    @Override
    public void update(NursingProjectVo bean) {
        nursingProjectMapper.update(bean);
    }

    @Override
    public void deleteById(Long id) {
        nursingProjectMapper.deleteByIdBed(id);
    }

    @Override
    public void updateBySta(Long id, Integer status) {
        nursingProjectMapper.updateBySta(id, status);
    }

    @Override
    public List<NursingProjectVo> findAll() {
        List<NursingProject> list=nursingProjectMapper.selectAll();
        return BeanUtil.copyToList(list,NursingProjectVo.class);
    }
}
